package com.order.appfood.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.order.appfood.domain.AppFood;
import com.order.appfood.service.IAppFoodService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * APP视频管理Controller
 * 
 * @author huhu
 * @date 2020-09-04
 */
@Controller
@RequestMapping("/order/appfood")
public class AppFoodController extends BaseController
{
    private String prefix = "order/appfood";

    @Autowired
    private IAppFoodService appFoodService;

    @RequiresPermissions("order:appfood:view")
    @GetMapping()
    public String appfood()
    {
        return prefix + "/appfood";
    }

    /**
     * 查询APP视频管理列表
     */
    @RequiresPermissions("order:appfood:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppFood appFood)
    {
        startPage();
        List<AppFood> list = appFoodService.selectAppFoodList(appFood);
        return getDataTable(list);
    }

    /**
     * 导出APP视频管理列表
     */
    @RequiresPermissions("order:appfood:export")
    @Log(title = "APP视频管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppFood appFood)
    {
        List<AppFood> list = appFoodService.selectAppFoodList(appFood);
        ExcelUtil<AppFood> util = new ExcelUtil<AppFood>(AppFood.class);
        return util.exportExcel(list, "appfood");
    }

    /**
     * 新增APP视频管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存APP视频管理
     */
    @RequiresPermissions("order:appfood:add")
    @Log(title = "APP视频管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppFood appFood)
    {
        return toAjax(appFoodService.insertAppFood(appFood));
    }

    /**
     * 修改APP视频管理
     */
    @GetMapping("/edit/{foodId}")
    public String edit(@PathVariable("foodId") Long foodId, ModelMap mmap)
    {
        AppFood appFood = appFoodService.selectAppFoodById(foodId);
        mmap.put("appFood", appFood);
        return prefix + "/edit";
    }

    /**
     * 修改保存APP视频管理
     */
    @RequiresPermissions("order:appfood:edit")
    @Log(title = "APP视频管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppFood appFood)
    {
        return toAjax(appFoodService.updateAppFood(appFood));
    }

    /**
     * 删除APP视频管理
     */
    @RequiresPermissions("order:appfood:remove")
    @Log(title = "APP视频管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(appFoodService.deleteAppFoodByIds(ids));
    }
}
